package cn.xm.lingshi.controller;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import cn.xm.lingshi.pojo.Brand;
import cn.xm.lingshi.pojo.User;
import cn.xm.lingshi.pojo.YongHu;
import cn.xm.lingshi.service.ShopService;
import cn.xm.lingshi.service.YonghuService;
import cn.xm.lingshi.service.impl.ShopServiceImpl;
import cn.xm.lingshi.service.impl.YongHuServiceImpl;

import com.alibaba.fastjson.JSON;

public class PwdServlet extends HttpServlet {

	
	private static final long serialVersionUID = 1L;

	
	public void destroy() {
		super.destroy(); // Just puts "destroy" string in log
		// Put your code here
	}

	
	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		doPost(request, response);
	}

	
	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		response.setContentType("text/html;charset=UTF-8");
		PrintWriter out = response.getWriter();
		// 接收请求数据
		request.setCharacterEncoding("UTF-8");
		YongHu users=(YongHu)request.getSession().getAttribute("denglu");
		//实验
		
		String password=request.getParameter("oldpwd");
		String or="1";
		if(!password.equals(users.getPassWord())){
			or="0";
		}else{
			String newPassword=request.getParameter("newpwd1");
			YonghuService user=new YongHuServiceImpl();
			user.modpassword(users.getUserId(), newPassword);
		}
		//响应JSON格式的数据
		out.print(JSON.toJSONString(or));
		out.flush();
		out.close();
	}

	
	public void init() throws ServletException {
		
	}

}
